package cn.hg.jbsa.admin.provider;

import java.util.List;

import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.SqlPara;

import cn.hg.jboot.core.exception.BaseServiceException;
import cn.hg.jbsa.admin.model.JbsaAdmin;
import cn.hg.jbsa.admin.model.JbsaRole;
import cn.hg.jbsa.admin.service.JbsaRoleService;
import io.jboot.aop.annotation.Bean;
import io.jboot.service.JbootServiceBase;

@Bean
public class JbsaRoleServiceProvider extends JbootServiceBase<JbsaRole> implements JbsaRoleService {

    @Override
    public List<JbsaRole> findByAdmin(JbsaAdmin admin) {
        /*
         * 通过SQL模板引擎构建SQL及参数
         */
        SqlPara sqlPara = Db.getSqlPara("system.findRolesByAdmin", Kv.by("admin", admin));

        /*
         * 执行查询
         */
        List<JbsaRole> result = JbsaRole.dao.find(sqlPara);

        /*
         * 返回查询结果
         */
        return result;
    }

    @Override
    public Page<JbsaRole> findPageByKv(Integer page, Integer limit, Kv para) throws BaseServiceException {
        /*
         * 通过SQL模板引擎构建SQL及参数
         */
        SqlPara sqlPara = Db.getSqlPara("system.findRole", para);

        /*
         * 执行查询
         */
        Page<JbsaRole> result = JbsaRole.dao.paginate(page, limit, sqlPara);

        /*
         * 返回查询结果
         */
        return result;
    }

}
